package com.iot.core.redis;

import com.google.common.collect.Sets;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.HostAndPort;

import java.util.Set;

/**
 * @ClassName JedisCluster
 * @Description 扩展JedisCluster，构造无参构造函数
 * @Author DuWei
 * @Date 2019/1/24 14:26
 **/
public class JedisCluster extends redis.clients.jedis.JedisCluster {

    private static GenericObjectPoolConfig genericObjectPoolConfig = RedisConfig.genericObjectPoolConfig;
    private static int connectionTimeout = RedisConfig.connectionTimeout;
    private static int soTimeout = RedisConfig.soTimeout;
    private static int maxRedirections = RedisConfig.maxRedirections;
    private static Set<String> jedisClusterNodes = RedisConfig.jedisClusterNodes;
    private static Set<HostAndPort> haps = Sets.newHashSet();
    private static String password = RedisConfig.password;

    static {
        //判断地址是否为空
        if(jedisClusterNodes == null || jedisClusterNodes.size() == 0){
            throw new NullPointerException("jedisClusterNodes is null.");
        }
        //构造结点
        for(String node:jedisClusterNodes){
            String[] arr = node.split(":");
            haps.add(new HostAndPort(arr[0],Integer.valueOf(arr[1])));
        }
    }

    public JedisCluster() {
        super(haps, connectionTimeout, soTimeout, maxRedirections, password, genericObjectPoolConfig);
    }

    public JedisCluster(HostAndPort node) {
        super(node);
    }

    public JedisCluster(HostAndPort node, int timeout) {
        super(node, timeout);
    }

    public JedisCluster(HostAndPort node, int timeout, int maxAttempts) {
        super(node, timeout, maxAttempts);
    }

    public JedisCluster(HostAndPort node, GenericObjectPoolConfig poolConfig) {
        super(node, poolConfig);
    }

    public JedisCluster(HostAndPort node, int timeout, GenericObjectPoolConfig poolConfig) {
        super(node, timeout, poolConfig);
    }

    public JedisCluster(HostAndPort node, int timeout, int maxAttempts, GenericObjectPoolConfig poolConfig) {
        super(node, timeout, maxAttempts, poolConfig);
    }

    public JedisCluster(HostAndPort node, int connectionTimeout, int soTimeout, int maxAttempts, GenericObjectPoolConfig poolConfig) {
        super(node, connectionTimeout, soTimeout, maxAttempts, poolConfig);
    }

    public JedisCluster(HostAndPort node, int connectionTimeout, int soTimeout, int maxAttempts, String password, GenericObjectPoolConfig poolConfig) {
        super(node, connectionTimeout, soTimeout, maxAttempts, password, poolConfig);
    }

    public JedisCluster(Set<HostAndPort> nodes) {
        super(nodes);
    }

    public JedisCluster(Set<HostAndPort> nodes, int timeout) {
        super(nodes, timeout);
    }

    public JedisCluster(Set<HostAndPort> nodes, int timeout, int maxAttempts) {
        super(nodes, timeout, maxAttempts);
    }

    public JedisCluster(Set<HostAndPort> nodes, GenericObjectPoolConfig poolConfig) {
        super(nodes, poolConfig);
    }

    public JedisCluster(Set<HostAndPort> nodes, int timeout, GenericObjectPoolConfig poolConfig) {
        super(nodes, timeout, poolConfig);
    }

    public JedisCluster(Set<HostAndPort> jedisClusterNode, int timeout, int maxAttempts, GenericObjectPoolConfig poolConfig) {
        super(jedisClusterNode, timeout, maxAttempts, poolConfig);
    }

    public JedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout, int soTimeout, int maxAttempts, GenericObjectPoolConfig poolConfig) {
        super(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, poolConfig);
    }

    public JedisCluster(Set<HostAndPort> jedisClusterNode, int connectionTimeout, int soTimeout, int maxAttempts, String password, GenericObjectPoolConfig poolConfig) {
        super(jedisClusterNode, connectionTimeout, soTimeout, maxAttempts, password, poolConfig);
    }
}
